package com.ejlchina.tool.fragment.offline

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.navigation.fragment.findNavController
import com.adolf.androiddemo.R
import com.adolf.androiddemo.databinding.FragmentNoDeviceBinding
import com.adolf.androiddemo.databinding.FragmentNoDeviceOfflineBinding
import com.ejlchina.tool.MainActivity
import com.ejlchina.tool.base.BaseBindingFragment2
import com.ejlchina.tool.constant.DEVICE_MODE_ONLINE
import com.ejlchina.tool.extension.safeNavigate

class NoDeviceOfflineFragment: BaseBindingFragment2<FragmentNoDeviceOfflineBinding>() {

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        setHeadVisibility(View.GONE)
        setActionBarPadding(false)
        dismissLoading()
        initListeners()
        checkHasConnectDeviceAndNavigate()
    }

    private fun initListeners(){
        binding.ivMenu.setOnClickListener {
            (requireActivity() as MainActivity).openDraw()
        }

        binding.btnOpenBluetooth.setOnClickListener {
            findNavController().safeNavigate(R.id.action_no_device_offline_to_scan_offline)
        }
    }

    private fun checkHasConnectDeviceAndNavigate(){
        if (viewModelActivity.getAllConnectDevicesCount() > 0){
            findNavController().safeNavigate(R.id.action_no_device_to_offline_config)
        }
    }
    override fun getViewBinding(inflater: LayoutInflater, container: ViewGroup): FragmentNoDeviceOfflineBinding {
        return FragmentNoDeviceOfflineBinding.inflate(inflater,container,true)
    }
}